package com.lap.framework.generator.domain.template.strategy;

import com.lap.framework.generator.application.assembler.Transformer;
import com.lap.framework.generator.domain.FileModel;
import com.lap.framework.generator.domain.TemplateModel;
import com.lap.framework.generator.domain.template.CodeContext;
import com.lap.framework.generator.domain.template.CodeTemplate;
import com.lap.framework.generator.domain.template.TemplateGenerator;
import com.lap.framework.generator.domain.valueobject.CodeType;
import java.util.List;

public class QueryMapper implements CodeTemplate<FileModel> {

  @Override
  public CodeType getType() {
    return CodeType.DRIVING;
  }

  @Override
  public List<FileModel> generate(CodeContext context) {
    TemplateModel model = Transformer.transform(context.tableMeta(), context.envConfig());
    String[] queryPackName = {
      model.getBasePackage(), "adapter.driving.query", model.getModule(), "mapper"
    };
    String[] queryMapperFileName = {model.getClassName(), "QueryMapper"};
    String[] queryMapperXmlFileName = {model.getClassName(), "QueryMapper"};

    return List.of(
        TemplateGenerator.generateFile(
            model,
            queryPackName,
            queryMapperFileName,
            "java",
            "adapter/driving/QueryMapper.java.ftl"),
        TemplateGenerator.generateFile(
            model,
            queryPackName,
            queryMapperXmlFileName,
            "xml",
            "adapter/driving/QueryMapper.xml.ftl"));
  }
}
